package orm

// IOrm 是 Orm (对象关系映射)模块的接口。直接暴露给用户的CRUD等一系列API。
type IOrm interface {
	IApi
	IQuery
	IExecute
	IOrmSession
	Close()
	Sql(operationType ...string) (string, []interface{}, error) // 原(BuildSql)构建 Sql 指令。即: CRUD。参数<operationType>只能是(select, insert, update, delete)
	Table(tab interface{}) IOrm
	// fields=select
	Field(fields ...string) IOrm
	AddField(fields ...string) IOrm
	// distinct 方法允许你强制查询返回不重复的结果集：
	Distinct() IOrm
	Data(data interface{}) IOrm
	Group(group string) IOrm
	Having(having string) IOrm
	Order(order string) IOrm
	Limit(limit int) IOrm
	Offset(offset int) IOrm
	Page(page int) IOrm
	// join(=innerJoin),leftJoin,rightJoin,crossJoin
	Join(args ...interface{}) IOrm
	LeftJoin(args ...interface{}) IOrm
	RightJoin(args ...interface{}) IOrm
	CrossJoin(args ...interface{}) IOrm
	// ` Where`,` Or`,` Null / NotNull`,` In / NotIn / OrIn / OrNotIn`,` Between / OrBetween / OrNotBetween / OrNotBetween`
	Where(args ...interface{}) IOrm
	And(args ...interface{}) IOrm
	Or(args ...interface{}) IOrm
	Null(arg string) IOrm
	OrNull(arg string) IOrm
	NotNull(arg string) IOrm
	OrNotNull(arg string) IOrm
	Regexp(arg string, expstr string) IOrm
	OrRegexp(arg string, expstr string) IOrm
	NotRegexp(arg string, expstr string) IOrm
	OrNotRegexp(arg string, expstr string) IOrm
	In(needle string, hystack []interface{}) IOrm
	OrIn(needle string, hystack []interface{}) IOrm
	NotIn(needle string, hystack []interface{}) IOrm
	OrNotIn(needle string, hystack []interface{}) IOrm
	Between(needle string, hystack []interface{}) IOrm
	OrBetween(needle string, hystack []interface{}) IOrm
	NotBetween(needle string, hystack []interface{}) IOrm
	OrNotBetween(needle string, hystack []interface{}) IOrm
	GetDriver() string
	SetBindValues(v interface{})
	GetBindValues() []interface{}
	ClearBindValues()
	TX(closers ...func(db IOrm) error) (err error) //事务
	Reset() IOrm
	ResetTable() IOrm
	ResetWhere() IOrm
	GetISession() ISession
	GetOrmApi() *Api
	// 悲观锁使用
	// sharedLock(lock in share mode) 不会阻塞其它事务读取被锁定行记录的值
	SharedLock() *Orm
	// 此外你还可以使用 lockForUpdate 方法。“for update”锁避免选择行被其它共享锁修改或删除：
	// 会阻塞其他锁定性读对锁定行的读取（非锁定性读仍然可以读取这些记录，lock in share mode 和 for update 都是锁定性读）
	LockForUpdate() *Orm
}
